package com.example.smartclassroom.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.smartclassroom.entity.Examplan;
import com.example.smartclassroom.mapper.ExamplanMapper;
import com.example.smartclassroom.service.ExamplanService;
import com.example.smartclassroom.util.DateUtil;
import com.example.smartclassroom.util.JsonDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class ExamplanServiceImpl extends ServiceImpl<ExamplanMapper, Examplan> implements ExamplanService {
    @Autowired
    private ExamplanMapper examplanMapper;

    /**
     * 添加考试安排
     * @param examplan
     * @return
     */
    public JsonDate addExamplan(Examplan examplan) {
        JsonDate date=new JsonDate();
        examplan.setTime(DateUtil.now());
        Integer rows= examplanMapper.insert(examplan);
        if (rows>0){
            date.setCode(0);
            date.setMsg("success");
        }else {
            date.setCode(1);
            date.setMsg("fail");
        }
        return date;
    }

    /**
     * 删除考试安排
     * @param ids
     * @return
     */
    public JsonDate deleteExamplan(Integer[] ids){
        JsonDate date=new JsonDate();
        Integer rows= examplanMapper.deleteBatchIds(Arrays.asList(ids));
        if (rows>0){
            date.setCode(0);
            date.setMsg("success");
        }else {
            date.setCode(1);
            date.setMsg("fail");
        }
        return date;
    }

    /**
     * 修改考试安排
     * @param examplan
     * @return
     */
    public JsonDate updateExamplan(Examplan examplan) {
        JsonDate date=new JsonDate();
        Integer rows=examplanMapper.updateById(examplan);
        if (rows>0){
            date.setCode(0);
            date.setMsg("success");
        }else {
            date.setCode(1);
            date.setMsg("fail");
        }
        return date;
    }

    /**
     * 查询所有考试安排
     * @param examplan
     * @return
     */
    public JsonDate queryAllExamplan(Examplan examplan) {
        JsonDate date=new JsonDate();
        date.setAge1(examplanMapper.queryTotal(examplan));
        date.setData(examplanMapper.selectAll(examplan));
        return date;
    }


    /**
     * 根据id查询考试安排
     * @param id
     * @return
     */
    public Examplan queryExamplanById(Integer id) {
        return examplanMapper.selectById(id);
    }

}
